package com.po;

import java.util.Date;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * OpUserAudit entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.po.OpUserAudit
 * @author MyEclipse Persistence Tools
 */

public class OpUserAuditDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(OpUserAuditDAO.class);
	// property constants
	public static final String ACT_TYPE = "actType";
	public static final String DEPT_ID = "deptId";
	public static final String IP = "ip";
	public static final String SUBSYSTEM_ID = "subsystemId";

	public void save(OpUserAudit transientInstance) {
		log.debug("saving OpUserAudit instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(OpUserAudit persistentInstance) {
		log.debug("deleting OpUserAudit instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public OpUserAudit findById(java.lang.String id) {
		log.debug("getting OpUserAudit instance with id: " + id);
		try {
			OpUserAudit instance = (OpUserAudit) getSession().get(
					"com.po.OpUserAudit", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(OpUserAudit instance) {
		log.debug("finding OpUserAudit instance by example");
		try {
			List results = getSession().createCriteria("com.po.OpUserAudit")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding OpUserAudit instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from OpUserAudit as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByActType(Object actType) {
		return findByProperty(ACT_TYPE, actType);
	}

	public List findByDeptId(Object deptId) {
		return findByProperty(DEPT_ID, deptId);
	}

	public List findByIp(Object ip) {
		return findByProperty(IP, ip);
	}

	public List findBySubsystemId(Object subsystemId) {
		return findByProperty(SUBSYSTEM_ID, subsystemId);
	}

	public List findAll() {
		log.debug("finding all OpUserAudit instances");
		try {
			String queryString = "from OpUserAudit";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public OpUserAudit merge(OpUserAudit detachedInstance) {
		log.debug("merging OpUserAudit instance");
		try {
			OpUserAudit result = (OpUserAudit) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(OpUserAudit instance) {
		log.debug("attaching dirty OpUserAudit instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(OpUserAudit instance) {
		log.debug("attaching clean OpUserAudit instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}